$(document).ready(function () {
    /*未登录跳转至登录页面*/
    $.ajax({
        url:interfaceGetState+generateMixed(9),
        type:'post',
        success:function (data) {
            if(data.status!=0){
                alert("请先登录");
                window.location.href="/f/campusinfo/login"+generateMixed(9);
            }else {
                /*个人中心页,获取用户名*/
                // if(window.sessionStorage){
                //     if(localStorage.getItem("user")){
                //         $("#person-background-name").html(localStorage.getItem('user'));
                //     }else {
                //         // window.location="/f/campusinfo/login";
                //     }
                // }
                $.ajax({
                    url:interfacePersonMsg+generateMixed(9),
                    type:'post',
                    success:function (data) {
                        if(data.data.name=='undefined'){
                            $("#person-background-name").html("暂无用户名信息");
                        }else {
                            $("#person-background-name").html(data.data.name);
                        }
                    },
                    error:function(){
                        $("#person-background-name").html("获取用户名失败");
                    }

                })
                /*用户退出*/
                $("#userExit").on("tap",function () {
                    console.log("1");
                    $("#grayLayer").height($(document).height());
                    $("#exit").slideDown("slow");
                    $(".exit").eq(0).on("tap",function () {
                       // 请求退出
                        $.ajax({
                            url:interfaceUserExit+generateMixed(9),
                            type:'post',
                            success:function (data) {
                                if(window.sessionStorage){
                                    sessionStorage.clear(); //清除所有sessionsorage
                                    localStorage.clear();
                                }
                                    window.location="/f/campusinfo/login"+generateMixed(9);
                            },
                            error:function() {
                                //错误提示
                            }
                        });
                    });
                    $(".exit").eq(1).click(function () {
                        setTimeout(function () {
                            $(this).css("background-color","#46ca98");
                        },100);
                        console.log("cancel");
                        $("#exit").slideUp("slow");
                        $("#grayLayer").height("0px");
                    })
                });
                /*个人中心，点击跳转（个人信息，我的报名，帮助中心，关于我们）*/
                $(".border-4").click(function () {
                    var index=$(".border-4").index(this);
                    switch (index){
                        case 0:            //跳转至个人信息页
                            window.location.href="/f/campusinfo/personMsg1"+generateMixed(9);
                            break;
                        case 1:             //跳转至我的报名页
                            window.location.href="/f/campusinfo/MyApply"+generateMixed(9);
                            break;
                        case 2:             //跳转至帮助中心
                            window.location.href="/f/campusinfo/helpCenter"+generateMixed(9);
                            break;
                        case 3:             //跳转至关于我们
                            window.location.href="/f/campusinfo/aboutUs"+generateMixed(9);
                            break;
                        case 4:             //跳转至我的问题
                            window.location.href="/f/campusinfo/myQuestions"+generateMixed(9);
                            break;
                    }
                });
            }
            var personMsg=[];
            $.ajax({
                url:interfacePersonMsg+generateMixed(9),
                type:'post',
                success:function(data){
                    if(data.status==0){
                        $("#collegename").text(data.data.schoolName);  //学校
                        $("#stuId").text(data.data.stuId);  //学号
                        $("#studentname").text(data.data.name);  //姓名
                        $("#mobile").text(data.data.mobile);    //手机
                        $("#email").text(data.data.email);      //邮箱
                        personMsg=[data.data.schoolId,data.data.stuId,data.data.name,data.data.mobile,data.data.email];
                    }
                    /*点击个人信息进入修改信息页面*/
                    $(".alterMsg").on("tap",function () {
                        var index=$(".alterMsg").index(this);
                        console.log(index);
                        if(window.sessionStorage){
                            sessionStorage.setItem("alterMsg",index);
                            sessionStorage.setItem("personMsg",personMsg[index]);
                            if(index!=5){      //修改信息
                                if(index==3){
                                    window.location.href="/f/campusinfo/alterPhoneNo"+generateMixed(9);  //修改手机号码
                                }else {
                                    window.location.href = "/f/campusinfo/alterPersonMsg"+generateMixed(9);
                                }
                            }else {          //修改密码
                                    window.location.href="/f/campusinfo/alterPassword"+generateMixed(9);
                            }
                        }else {
                            if (index != 5) {
                                if (index==3) {
                                    window.location.href = "/f/campusinfo/alterPhoneNo"+generateMixed(9);  //修改手机号码
                                } else {
                                    window.location.href = "/f/campusinfo/alterPersonMsg?index=" + index+generateMixed(9);  //修改信息
                                }
                            } else {
                                window.location.href = "/f/campusinfo/alterPassword"+generateMixed(9);   //修改密码
                            }
                        }
                    });
                }
            });
        },
        error:function () {
            alert("error");
        }
    });
})